﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Services.Description;
using System.Web.UI.WebControls;
using DLV.Data.Entities;
using DLV.FrameWork;

namespace DLV.BackEnd.Pages
{
    public partial class EditTourService : AdminPageBase
    {
        protected int Type = 0;
        protected int scheduleType = 0;
        protected List<ServiceInfo> ServiceList = new List<ServiceInfo>();

        protected void Page_Load(object sender, EventArgs e)
        {
           LoadDefault();
            ServiceList = new ServiceController().ListService();
        }

        protected void lbtSave_Click(object sender, EventArgs e)
        {
            SaveData();
        }

        public void SaveData()
        {
            if (rdMayBay.Checked)
            {
                
            }
        }
        protected void lbtClose_Click(object sender, EventArgs e)
        {
            //Response.Redirect("/Pages/ListAge.aspx?xml=Age");
        }

        protected void Service_CheckedChanged(object sender, EventArgs e)
        {
            if (rdPhuongTien.Checked)
            {
                rdMayBay.Visible = true;
                rdTauHoa.Visible = true;
                rdOto.Visible = true;
            }
            if (rdKhachsan.Checked)
            {
                lbNational.Visible = true;
                lbCity.Visible = true;
                lbHotelType.Visible = true;
                lbHotel.Visible = true;

                ddlNational.Visible = true;
                ddlCity.Visible = true;
                ddlHotelType.Visible = true;
                ddlHotel.Visible = true;

                lbLocation.Visible = false;
                ddlLocation.Visible = false;
                lbService.Visible = false;
                txtServicePopup.Visible = false;
                lbRestaurant.Visible = false;
                ddlRestaurant.Visible = false;
                lbRestaurantType.Visible = false;
                ddlVisa.Visible = false;
                ddlInsurance.Visible = false;
                ddlPartner.Visible = false;

                LoadNational();
                LoadHotelType();

            }
            if (rdNhaHang.Checked)
            {
                lbNational.Visible = true;
                lbCity.Visible = true;
                lbRestaurantType.Visible = true;
                lbRestaurant.Visible = true;

                ddlNational.Visible = true;
                ddlCity.Visible = true;
                ddlHotelType.Visible = true;
                ddlHotel.Visible = false;
                lbHotel.Visible = false;
                
                lbLocation.Visible = false;
                ddlLocation.Visible = false;
                lbService.Visible = false;
                txtServicePopup.Visible = false;

                ddlVisa.Visible = false;
                ddlInsurance.Visible = false;
                ddlRestaurant.Visible = true;
                ddlPartner.Visible = false;

                LoadNational();
                LoadHotelType();
            }
            if (rdVisa.Checked)
            {
                lbVisaType.Visible = true;
                lbVisa.Visible = true;
                ddlVisa.Visible = true;
                ddlPartner.Visible = true;
                ddlInsurance.Visible = false;

                LoadPartner();
                }
            if (rdBaoHiem.Checked)
            {
                lbInsurance.Visible = true;
                ddlVisa.Visible = false;
                ddlInsurance.Visible = true;
                ddlPartner.Visible = false;

                LoadInsurance();
            }
            if (rdDichVu.Checked)
            {
                lbService.Visible = true;
                //ddlHotel.Visible = true;

                lbNational.Visible = true;
                lbCity.Visible = true;

                ddlNational.Visible = true;
                ddlCity.Visible = true;
                lbHotel.Visible = false;
                lbHotelType.Visible = false;
                ddlHotel.Visible = false;
                ddlHotelType.Visible = false;
                lbLocation.Visible = true;
                ddlLocation.Visible = true;
                
                ddlPartner.Visible = false;
                ddlVisa.Visible = false;
                ddlInsurance.Visible = false;

                txtServicePopup.Visible = true;
                LoadNational();
                
            }
            //RadioButton selectedRadioButton = (RadioButton)sender;
            //lblResult.Text = selectedRadioButton.Text;

        }

        //public void Location_SelectedIndexChange(object sender, EventArgs e)
        //{
        //    int locationId = int.Parse(ddlLocation.SelectedValue);
        //    ServiceList = new ServiceController().ListService().Where(p => p.LocationId == locationId).ToList();
        //}

        protected void TranSport_CheckedChanged(object sender, EventArgs e)
        {
            //RadioButton selectedRadioButton = (RadioButton)sender;
            if (rdMayBay.Checked)
            {
                lbConcernAir.Visible = true;
                Type = 1;
                scheduleType = 1;
            }
            if (rdTauHoa.Checked)
            {
                lbConcernStation.Visible = true;
                Type = 2;
                scheduleType = 2;
            }
            if (rdOto.Checked)
            {
                lbConcernCar.Visible = true;
                Type = 3;
                scheduleType = 4;
            }


            LoadConcern();
            rdMayBay.Visible = true;
            rdTauHoa.Visible = true;
            rdOto.Visible = true;

           // lbSchedule.Visible = true;
            ddlConcern.Visible = true;
           // ddlSchedule.Visible = true;

            lbBeginLocation.Visible = true;
            lbEndLocation.Visible = true;
            ddlBeginLocation.Visible = true;
            ddlEndLocation.Visible = true;

            LoadLocationDefault();
            //lblResult.Text = selectedRadioButton.Text;

        }

        public void LoadDefault()
        {
            rdMayBay.Visible = false;
            rdTauHoa.Visible = false;
            rdOto.Visible = false;

            lbConcernAir.Visible = false;
            lbConcernCar.Visible = false;
            lbConcernStation.Visible = false;
            //lbSchedule.Visible = false;
            lbNational.Visible = false;
            lbCity.Visible = false;
            lbHotelType.Visible = false;
            lbRestaurantType.Visible = false;
            lbTypeCar.Visible = false;
            lbVisaType.Visible = false;
            lbCar.Visible = false;
            lbInsurance.Visible = false;
            lbRestaurant.Visible = false;
            lbService.Visible = false;
            lbVisa.Visible = false;
            lbHotel.Visible = false;

            ddlConcern.Visible = false;
           // ddlSchedule.Visible = false;
            ddlNational.Visible = false;
            ddlCity.Visible = false;
            ddlHotelType.Visible = false;
            ddlHotel.Visible = false;

            lbBeginLocation.Visible = false;
            lbEndLocation.Visible = false;
            ddlBeginLocation.Visible = false;
            ddlEndLocation.Visible = false;

            ddlRestaurant.Visible = false;
            ddlVisa.Visible = false;
            ddlInsurance.Visible = false;
            ddlPartner.Visible = false;
            
            lbLocation.Visible = false;
            ddlLocation.Visible = false;
            txtService.Visible = false;
            txtServicePopup.Visible = false;
        }

        public void LoadConcern()
        {
            ddlConcern.DataSource = new ConcernController().ListConcernByType(Type);
            ddlConcern.DataTextField = "ConcernFullName";
            ddlConcern.DataValueField = "ConcernId";
            ddlConcern.DataBind();
            if (Type == 1 || Type == 2)
            {
                ddlConcern.Items.Insert(0, new ListItem("---Chọn hãng---", "-1"));
            }
            if(Type==3)
            {
                ddlConcern.Items.Insert(0, new ListItem("---Chọn hiệu xe---", "-1"));
            }
        }

        public void LoadNational()
        {
            ddlNational.DataSource = new NationalController().ListNational();
            ddlNational.DataValueField = "NationalId";
            ddlNational.DataTextField = "NationalName";
            ddlNational.DataBind();

            ddlNational.Items.Insert(0,new ListItem("---Chọn quốc gia---","-1"));
        }
        public void LoadPartner()
        {
            ddlPartner.DataSource = new PartnerController().ListPartner();
            ddlPartner.DataValueField = "PartnerId";
            ddlPartner.DataTextField = "PartnerName";
            ddlPartner.DataBind();

            ddlPartner.Items.Insert(0, new ListItem("---Chọn nhà cung cấp---", "-1"));
        }
        public void LoadInsurance()
        {
            ddlInsurance.DataSource = new InsuranceController().ListInsurance();
            ddlInsurance.DataValueField = "InsuranceId";
            ddlInsurance.DataTextField = "InsuranceName";
            ddlInsurance.DataBind();

            ddlInsurance.Items.Insert(0, new ListItem("---Chọn bảo hiểm---", "-1"));
        }
        private void LoadLocationDefault()
        {
            var locations = new LocationController().ListLocationByScheduleType(scheduleType);

            ddlBeginLocation.DataSource = locations;
            ddlBeginLocation.DataTextField = "LocationName";
            ddlBeginLocation.DataValueField = "LocationId";
            ddlBeginLocation.DataBind();
            ddlBeginLocation.Items.Insert(0, new ListItem("--- Chọn điểm đi ---", "-1"));

            ddlEndLocation.DataSource = locations;
            ddlEndLocation.DataTextField = "LocationName";
            ddlEndLocation.DataValueField = "LocationId";
            ddlEndLocation.DataBind();
            ddlEndLocation.Items.Insert(0, new ListItem("--- Chọn điểm đến ---", "-1"));
        }

        private void LoadHotelType()
        {
            if (rdKhachsan.Checked)
            {
                ddlHotelType.DataSource = new HotelTypeController().ListHotelType();
                ddlHotelType.DataValueField = "HotelTypeId";
                ddlHotelType.DataTextField = "HotelTypeName";
                ddlHotelType.DataBind();

                ddlHotelType.Items.Insert(0, new ListItem("---Chọn loại khách sạn---", "-1"));
            }
            if (rdNhaHang.Checked)
            {
                ddlHotelType.DataSource = new RestaurantTypeController().ListRestaurantType();
                ddlHotelType.DataValueField = "RestaurantTypeId";
                ddlHotelType.DataTextField = "RestaurantTypeName";
                ddlHotelType.DataBind();

                ddlHotelType.Items.Insert(0, new ListItem("---Chọn loại nhà hàng---", "-1"));
            }
        }
    }
}